package pap.test.fcPuCc;
import gov.nasa.jpf.jvm.Verify;

public class SimpleBody extends Body {

	private double radius;

	public SimpleBody() {
		Verify.beginAtomic();
		this.mass = UtilMethods.getRandomDouble(10, 100);
		this.speed = UtilMethods.getRandom2DVector(1,
				5);
		this.massCenter = UtilMethods.getRandom2DPoint(0, 500, 0, 500);
		if (mass > 1000)
			radius = 20;
		else
			radius = mass / 5;
		Verify.endAtomic();
	}

	/**
	 * Two SimpleBody are colliding if the distance between their centers is
	 * less than the sum of their radius
	 */
	@Override
	public boolean intersect(SimpleBody body) {

		// Calculating the distance between bodies's centers
		double centersDistance = massCenter.distanceFrom(body.getMassCenter());

		// If this distance is less or equal than the sum of the radius, the
		// bodies are colliding
		if (centersDistance <= radius + body.radius - 2)
			return true;

		return false;
	}

	public double getRadius() {
		return radius;
	}
}
